/**
 * @file   1130.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Wed Jul  7 01:54:02 2021
 * 
 * @brief  PAT advanced 1130
 * 
 * 
 */
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
class TNode{
public:
    string data;
    int lc;
    int rc;
};
class Tree{
private:
    vector<TNode> Nodes;
    int nodenum;
    int root;
public:
    Tree(int d){
	nodenum=d;
    }
    void Build();
    void Traverse();
    string inorder(int index);
};
void Tree::Build(){
    map<int,bool> isvisible;
    for(int i=0;i<nodenum;i++){
	TNode T;
	string s;
	int l,r;
	cin>>s>>l>>r;
	T.data=s;
	if(l!=-1){
	    l--;
	    isvisible[l]=true;
	}
	if(r!=-1){
	    r--;
	    isvisible[r]=true;
	}
	T.lc=l;
	T.rc=r;
	Nodes.push_back(T);
    }
    for(int i=0;i<nodenum;i++){
	if(isvisible.count(i)==0){
	    root=i;
	    break;
	}
    }
}
void Tree::Traverse(){
    string str=inorder(root);
    cout<<str<<endl;
}
string Tree::inorder(int index){
    if(index==-1){
	return "";
    }
    if(Nodes[index].rc!=-1){
	Nodes[index].data=inorder(Nodes[index].lc)+Nodes[index].data+inorder(Nodes[index].rc);
	if(index!=root){
	    Nodes[index].data="("+Nodes[index].data+")";
	}
    }
    return Nodes[index].data;
}
int main(){
    int num;
    cin>>num;
    Tree T(num);
    T.Build();
    T.Traverse();
}
